#创建一个浏览器对象
import datetime
import os.path
import sys
from selenium import webdriver
from selenium.webdriver.edge.service import Service

edge_path=r"E:\Users\zzj20\Desktop\edgedriver_win64\msedgedriver.exe"
class Driver:
    driver=""
    def __init__(self):
        options=webdriver.EdgeOptions()
        self.driver=webdriver.Edge(service=Service(edge_path),options=options)
        self.driver.implicitly_wait(10)
    def getScreenShot(self):
        #创建屏幕截图
        #图片文件名称：./2025-08-19-171723.png
        #图片路径：../images/2025-08-19/2025-08-19-171723.png
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件夹是否已经存在，若不存在则创建文件夹
        if not os.path.exists("../images/"+dirname):
            os.mkdir("../images/"+dirname)
        #2025-08-19/2025-08-19-171723.png
        #图片路径：../images/2025-08-19/2025-08-19-171723.png
        filename=sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("../images/"+dirname+"/"+filename)

BlogDriver=Driver()